{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-16T09:00:53.499379Z",
     "start_time": "2025-09-16T09:00:53.490609Z"
    }
   },
   "source": [
    "# def CountDown(n):\n",
    "#     while n > 0:\n",
    "#         n -= 1\n",
    "# CountDown(100000000)\n",
    "\n",
    "# from threading import Thread\n",
    "# n = 100000000\n",
    "# t1 = Thread(target=CountDown, args=(n,))\n",
    "# t2 = Thread(target=CountDown, args=(n,))\n",
    "# t1.start()\n",
    "# t2.start()\n",
    "# t1.join()\n",
    "# t2.join()\n",
    "\n",
    "import threading\n",
    "n = 0\n",
    "def foo():\n",
    "    global n\n",
    "    n += 1\n",
    "threads = []\n",
    "for i in range(100):\n",
    "    t = threading.Thread(target=foo)\n",
    "    threads.append(t)\n",
    "for t in threads:\n",
    "    t.start()\n",
    "\n",
    "for t in threads:\n",
    "    t.join()\n",
    "print(n)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100\n"
     ]
    }
   ],
   "execution_count": 170
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
